local duanlongmai = fk.CreateSkill {
  name = "lingling__duanlongmai",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lingling__duanlongmai"] = "断龙脉",
  [":lingling__duanlongmai"] = "锁定技，回合结束时，没有手牌的角色各摸三张牌。结束阶段，你可以令一名没有手牌的其他角色减1点体力上限并摸一张牌。",

  ["#lingling__duanlongmai-choose"] = "断龙脉：你可以令一名没有手牌的其他角色减1点体力上限并摸一张牌！",
}

duanlongmai:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(duanlongmai.name) and player.phase == Player.Finish and
        table.find(player.room.alive_players, function(p)
          return p:isKongcheng() and p ~= player
        end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p)
      return p:isKongcheng() and p ~= player
    end)
    local to = room:askToChoosePlayers(player, {
      skill_name = duanlongmai.name,
      min_num = 1,
      max_num = 1,
      targets = targets,
      prompt = "#lingling__duanlongmai-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, { tos = to })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    player.room:changeMaxHp(to, -1)
    if not to.dead then
      to:drawCards(1, duanlongmai.name)
    end
  end,
})

duanlongmai:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(duanlongmai.name) and
        table.find(player.room.alive_players, function(p)
          return p:isKongcheng()
        end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      if p:isKongcheng() and not p.dead then
        p:drawCards(3, duanlongmai.name)
      end
    end
  end,
})

return duanlongmai
